package edu.zhangxu.service;


import edu.zhangxu.pojo.Problem;
import net.sf.json.JSONArray;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class MainTest {

    public static Map<String, Class> map = new HashMap<>();

    public static void main(String[] args) {
        String user = "root";
        String password = "123456";
        String url = "jdbc:mysql://192.168.1.36:3306/wecode";
        String sql = "INSERT INTO solutions(problem_id, judger, language, code, result) VALUES (?, ?, ?, ?, ?)";
        String code = "#include <stdio.h>\n" +
                "\n" +
                "int main(int argc, char** argv) {\n" +
                "    int a,b;\n" +
                "    scanf(\"%d%d\", &a, &b);\n" +
                "    printf(\"%d\\n\",a*b);\n" +
                "}\n" +
                "\n";

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(url, user, password);
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setInt(1, 0);
            ps.setString(2, "Master");
            ps.setInt(3, 0);
            ps.setString(4, code);
            ps.setInt(5, 0);
            int rtn = ps.executeUpdate();
//            ResultSet rs = ps.executeQuery();
//            while(rs.next()) {
//                rs.getInt("problemNo");
//                rs.getString("problemName");
//                rs.getDouble("problemPass");
//            }
//            rs.close();
            System.out.println("操作成功，" + rtn + "行受影响。");
            ps.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
